package org.generic.test05;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * @author CSY
 * @date 2025 - 03 - 16
 */
public class MainTest {
    public static void main(String[] args) {
        ArrayList<Employee> employees = new ArrayList<>();
        employees.add(new Employee("zs",5000,new MyDate(2004,07,02)));
        employees.add(new Employee("ls",5500,new MyDate(2001,05,20)));
        employees.add(new Employee("ws",13000,new MyDate(2004,12,14)));
        employees.add(new Employee("zs",13000,new MyDate(2004,12,14)));

        System.out.println(employees);

        employees.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee emp1, Employee emp2) {
                //先按照name排序，如果name相同，则按生日日期的先后排序。【即：定制排序】
                //先对传入的参数进行验证
                if (!(emp1 instanceof Employee && emp2 instanceof Employee)){
                    System.out.println("类型不正确...");
                    return 0;
                }
                //比较name
                int i = emp1.getName().compareTo(emp2.getName());
                if (i != 0){
                    return i;
                }
                //以下是对birthday的比较
                return emp1.getBirthday().compareTo(emp2.getBirthday());
            }
        });

        System.out.println("======================");
        System.out.println(employees);
    }
}
